package com.java.al.swing.filechooser;

import java.io.File;

import javax.swing.JFileChooser;

public class ChangeFileChooser {
  public static void main(String[] argv) {
    JFileChooser fileChooser = new JFileChooser(new File("."));
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.addChoosableFileFilter(new MyFilter());
    fileChooser.showOpenDialog(null);
    System.out.println(fileChooser.getSelectedFile());
  }
}

class MyFilter extends javax.swing.filechooser.FileFilter {
  public boolean accept(File file) {
    String filename = file.getName();
    return filename.toLowerCase().endsWith(".txt");
  }

  public String getDescription() {
    return "文本文档(*.txt)";
  }
}